package java.jdbc;

import java.sql.Connection;
import java.sql.Statement;

/**
 * 执行UPDATE语句
 */
public class JDBCDemo3 {
    public static void main(String[] args) throws Exception {
        /*
            根据用户名修改用户昵称

            UPDATE userinfo
            SET nickname='新昵称'
            WHERE username='用户名'
         */
        Connection connection = DBUtil.getConnection();
        Statement statement = connection.createStatement();
        String sql = "UPDATE userinfo " +
                     "SET nickname='晶晶' " +
                     "WHERE username='王克晶'";
        int num = statement.executeUpdate(sql);
        if(num>0){
            System.out.println("修改成功");
        }else{
            System.out.println("修改失败");
        }
        connection.close();
    }
}
